package com.demo.rabbitmq.producer;

import com.demo.rabbitmq.config.DeadExchangeEnum;
import com.demo.rabbitmq.config.DeadQueueEnum;
import com.demo.rabbitmq.config.DeadRoutingKeyEnum;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class DeadLetterProducer {

    @Resource
    private RabbitTemplate rabbitTemplate;

    public void send(int i) {
        String exchange = DeadExchangeEnum.DEAD_BUSINESS_EXCHANGE.getExchangeName();
        String routeKey = DeadRoutingKeyEnum.DEAD_BUSINESS_QUEUE_ROUTING_KEY.getRoutingKeyName();
        String content = String.format("死信消息=%d，hello world! 当前时间：%s", i, new Date());
        rabbitTemplate.convertAndSend(exchange, routeKey, content, new CorrelationData());
    }


}
